package com.webflux.controller;

import com.webflux.entity.TbCity;
import com.webflux.service.TbCityService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

@RestController
@RequestMapping("/city")
public class TbCityController {
    @Resource
    private TbCityService cityService;

    @PostMapping
    public Mono<TbCity> save(@RequestBody TbCity city) {
        return cityService.add(city);
    }

    @DeleteMapping
    public Mono<Void> delete(Integer id) {
        TbCity city = new TbCity();
        city.setId(id);
        return cityService.delete(city);
    }

    @PutMapping
    public Mono<TbCity> edit(@RequestBody TbCity city) {
        return cityService.edit(city);
    }

    @GetMapping("/{cityName}")
    public Flux<TbCity> search(@PathVariable String cityName) {
        return cityService.search(cityName);
    }

}
